package com.j.lemon.learn.basic;

import org.jasig.cas.client.authentication.AttributePrincipal;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "casServlet",urlPatterns = "/login")
public class CasServlet extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // cas认证成功，获取用户信息
        AttributePrincipal principal = (AttributePrincipal)req.getUserPrincipal();
        String name = principal.getName();
        System.out.println("账户名： " + name);
        HttpSession session=req.getSession();
        session.setAttribute("username",name);
//        req.getSession().setAttribute("username",name);
        req.getRequestDispatcher("/WEB-INF/success.jsp").forward(req,resp);
    }
}
